home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE09 / PSISBAR / PSISBAR.ZIP / psiStatusBar.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1996-03-14  |  9.9 KB  |  281 lines

  1. unit psiStatusBar;
  2.  
  3. {================================================================}
  4. { TpsiStatusBar - Version 1.1                                    }
  5. {================================================================}
  6. {                                                                }
  7. { 1.1 Changes                                                    }
  8. { ------------------------------------------------               }
  9. { *** AM/PM not displayed properly:                              }
  10. {     Typo!!!, TimeStr declared as string[10],                   }
  11. {       should've been string[11].                               }
  12. {     Time display appears to be correct now.                    }
  13. { *** Created procedure ShowDateTime:                            }
  14. {     Called when Date/Time display is updated                   }
  15. { *** Adjusted panel widths:                                     }
  16. {     To better accomodate months 10, 11, & 12                   }
  17. { *** Changed "Hint" handling:                                   }
  18. {     Changed ShowHint to True.                                  }
  19. {     Autofill Hint with panels.items[0].text (in timer event).  }
  20. {     If form has been resized and "text" is not visible,        }
  21. {       Hint allows user to see the "text".                      }
  22. {                                                                }
  23. {================================================================}
  24. {                                                                }
  25. { DELPHI 2.0 COMPONENT                                           }
  26. { FREEWARE                                                       }
  27. {                                                                }
  28. { TpsiStatusBar creates a "Win95" status bar                     }
  29. {    at the bottom of your form that automatically processes     }
  30. {    Date/Time (clock) updating.                                 }
  31. {                                                                }
  32. { !!Make sure to read the CONTROL "NAME" section that follows.!! }
  33. {                                                                }
  34. { TpsiStatusBar consists of 2 panels:                            }
  35. {    Panels.Items[0] - we use this panel for field "captions"    }
  36. {       The following command would display "Status Text"        }
  37. {            StatusBar.panels.items[0].text :='Status Text';     }
  38. {    Panels.Items[1] - is for date & time (automatically filled) }
  39. {                                                                }
  40. { There's no need to add a timer to fill the Date/Time,          }
  41. {    Timer processing is handled within the component.           }
  42. {                                                                }
  43. { The timer "interval" is hardcoded to 1 second                  }
  44. {    (1000 ms in procedure UpdateTimer)                          }
  45. { If there's another function you need to perform every second,  }
  46. {    it can be added to this control's "OnTimer" event.          }
  47. {                                                                }
  48. {----------------------------------------------------------------}
  49. {                                                                }
  50. { If it's helpful in some way, GREAT.                            }
  51. { As you'd expect, USE TpsiStatusBar AT YOUR OWN RISK.           }
  52. { If you use it, please send any comments.                       }
  53. { If you improve it, please let me know.                         }
  54. {                                                                }
  55. { Enjoy it,                                                      }
  56. { Jim Albert                                                     }
  57. {   PIN Systems, Inc.                                            }
  58. {     Compuserve -- 102426,2527                                  }
  59. {     Internet   -- PINSystems@mailhost.net                      }
  60. {                                                                }
  61. {================================================================}
  62.  
  63. {!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  64. { CONTROL "NAME"                                                 }
  65. {!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  66. {                                                                }
  67. { For compliance with other psi controls;                        }
  68. {    we set the name to "StatusBar", in the Resize event.        }
  69. {                                                                }
  70. { If you don't want the component automatically named            }
  71. {    "StatusBar", search for, and comment out the following      }
  72. {    line.                                                       }
  73. {        if Name <>'StatusBar' then Name :='StatusBar';          }
  74. {                                                                }
  75. {!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}
  76.  
  77. interface
  78.  
  79. uses
  80.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  81.   ComCtrls, psiMain;
  82.  
  83. {var}
  84.  
  85. type
  86.   TTimerID  =integer;
  87.  
  88. type
  89.   TpsiStatusBar = class(TStatusBar)
  90.   private
  91.     FOnResize: TNotifyEvent;
  92.     FOnTimer: TNotifyEvent;
  93.     FTimerID: integer;
  94.     FWindowHandle: HWND;
  95.     procedure WMSize(var Message: TWMSize); message WM_SIZE;
  96.     procedure SetOnTimer(Value: TNotifyEvent);
  97.     procedure ShowDateTime;
  98.     procedure UpdateTimer;
  99.     procedure WndProc(var Msg: TMessage);
  100.     property  TimerID: TTimerID read FTimerID write FTimerID;
  101.  
  102.   protected
  103.     procedure Timer; dynamic;
  104.  
  105.   public
  106.     constructor Create(AOwner: TComponent); override;
  107.      destructor Destroy; override;
  108.  
  109.   published
  110.     property Align;
  111.     property Cursor;
  112.     property DragCursor;
  113.     property DragMode;
  114.     property Enabled;
  115.     property Font;
  116.     property Height;
  117.     property HelpContext;
  118.     property Hint;
  119.     property Left;
  120.     property Name;
  121.     property Panels;
  122.     property ParentFont;
  123.     property ParentShowHint;
  124.     property PopupMenu;
  125.     property ShowHint;
  126.     property SimplePanel;
  127.     property SimpleText;
  128.     property SizeGrip;
  129.     property Tag;
  130.     property Top;
  131.     property Visible;
  132.     property Width;
  133.     property OnClick;
  134.     property OnDblClick;
  135.     property OnDragDrop;
  136.     property OnDragOver;
  137.     property OnDrawPanel;
  138.     property OnEndDrag;
  139.     property OnMouseDown;
  140.     property OnMouseMove;
  141.     property OnMouseUp;
  142.     property OnResize: TNotifyEvent read FOnResize write FOnResize;
  143.     property OnStartDrag;
  144.     property OnTimer: TNotifyEvent read FOnTimer write SetOnTimer;
  145.   end;
  146.  
  147. procedure Register;
  148.  
  149. implementation
  150.  
  151. constructor TpsiStatusBar.Create(AOwner: TComponent);
  152. var
  153.   TimeStr: string[11];
  154. begin
  155.   inherited Create(AOwner);
  156.   Align :=alBottom;
  157.   Cursor :=crDefault;
  158.   DragCursor :=crDrag;
  159.   DragMode :=dmManual;
  160.   Enabled :=True;
  161.   Font.Name := 'MS Sans Serif';
  162.   Font.Color := clBlack;
  163.   Font.Height := -11;
  164.   Font.Size := 8;
  165.   Font.Style := [];
  166.   FWindowHandle := AllocateHWnd(WndProc);
  167.   Height :=19;
  168.   HelpContext :=0;
  169.   Hint :='';
  170.   panels.add;
  171.   panels.items[0].text :='';
  172.   panels.items[0].width :=width-126;
  173.   panels.items[0].style :=psText;
  174.   panels.items[0].bevel :=pbLowered;
  175.   panels.items[0].alignment :=taLeftJustify;
  176.   panels.add;
  177.   panels.items[1].text :='';
  178.   panels.items[1].width :=width-panels.items[0].width;
  179.   panels.items[1].style :=psText;
  180.   panels.items[1].bevel :=pbLowered;
  181.   panels.items[1].alignment :=taLeftJustify;
  182.   ParentFont :=False;
  183.   ParentShowHint :=True;
  184.   ShowHint :=True;
  185.   SimplePanel :=False;
  186.   SimpleText :='';
  187.   SizeGrip :=True;
  188.   Tag :=0;
  189.   Visible :=True;
  190.   UpdateTimer;
  191.     { Don't wait 1 second to display the time }
  192.   ShowDateTime;
  193. end;
  194.  
  195.  
  196. destructor TpsiStatusBar.Destroy;
  197. begin
  198.   if TimerID >0 then KillTimer(FWindowHandle, 1);
  199.   DeallocateHWnd(FWindowHandle);
  200.   inherited Destroy;
  201. end;
  202.  
  203.  
  204. procedure Register;
  205. begin
  206.   RegisterComponents('psi', [TpsiStatusBar]);
  207. end;
  208.  
  209.  
  210. { Resize event }
  211. procedure TpsiStatusBar.WMSize(var Message: TWMSize);
  212. begin
  213.   if Assigned(FOnResize) then FOnResize(Self);
  214.   if GetParentForm(self).width >125 then
  215.     panels.items[0].width :=GetParentForm(self).width-126
  216.   else
  217.     panels.items[0].width :=0;
  218.     {====================================================}
  219.     { A resize is called after the object is created.    }
  220.     { If desired, the name can be set here.              }
  221.     {                                                    }
  222.     { For compliance with other psi components,          }
  223.     {    we set the name to "StatusBar".                 }
  224.     {                                                    }
  225.     {----------------------------------------------------}
  226.     {                                                    }
  227.     { If you don't want it automatically named           }
  228.     { "StatusBar", comment out the following line        }
  229.     {                                                    }
  230.     {====================================================}
  231.   if Name <>'StatusBar' then Name :='StatusBar';
  232. end;
  233.  
  234.  
  235. { Timer}
  236. procedure TpsiStatusBar.UpdateTimer;
  237. begin
  238.   if TimerID >0 then KillTimer(FWindowHandle, 1);
  239.   TimerID :=SetTimer(FWindowHandle, 1, 1000, nil)
  240. end;
  241.  
  242.  
  243. procedure TpsiStatusBar.WndProc(var Msg: TMessage);
  244. begin
  245.   with Msg do
  246.     if Msg = WM_TIMER then
  247.       try
  248.         Timer;
  249.       except
  250.         Application.HandleException(Self);
  251.       end
  252.     else
  253.       Result := DefWindowProc(FWindowHandle, Msg, wParam, lParam);
  254. end;
  255.  
  256.  
  257. procedure TpsiStatusBar.SetOnTimer(Value: TNotifyEvent);
  258. begin
  259.   FOnTimer := Value;
  260.   UpdateTimer;
  261. end;
  262.  
  263.  
  264. procedure TpsiStatusBar.Timer;
  265. begin
  266.   ShowDateTime;
  267.   Hint :=panels.items[0].text;
  268.   if Assigned(FOnTimer) then FOnTimer(Self);
  269. end;
  270.  
  271.  
  272. procedure TpsiStatusBar.ShowDateTime;
  273. var
  274.   TimeStr: string[11];
  275. begin
  276.   TimeStr :=TrimStr(TimeToStr(Time));
  277.   panels.items[1].text :=DateToStr(Date)+'  '+Copy(TimeStr,1,StrAt(TimeStr,':',2)-1)+' '+Lowercase(StrRight(TimeStr,2));
  278. end;
  279.  
  280. end.
  281.